$(document).ready(function(){	
	$(".product").on("change", function(){
		var id = $(this).val();
		var txt = this.options[this.selectedIndex].text;
		$.getJSON("/droowa/product/getProductInfo.do", {"id":id,"sort":txt}, callback);
	});
});

var cpu = 0;
var mainboard = 0;
var cooler = 0;
var memory = 0;
var graphic = 0;
var hdd = 0;
var ssd = 0;
var dvd = 0;
var sound = 0;
var power = 0;
var kase = 0;
var os = 0;
var keyboard = 0;
var moniter = 0;
var ram = 0;
var mouse = 0;
var sum = 0;

function callback(data){
	if(data.category=='CPU'){
		cpu = data.price;
		$("#cpu").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='마우스'){
		mouse = data.price;
		
	}else if(data.category=='파워'){
		power = data.price;
		$("#power").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='키보드'){
		keyboard = data.price;
		
	}else if(data.category=='케이스'){
		kase = data.price;
		$("#case").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='모니터'){
		moniter = data.price;
		
	}else if(data.category=='메인보드'){
		mainboard = data.price;
		$("#mainboard").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='쿨러'){
		cooler = data.price;
		$("#cooler").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='RAM'){
		memory = data.price;
		$("#memory").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='그래픽카드'){
		graphic = data.price;
		$("#graphic").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='HDD'){
		hdd = data.price;
		$("#hdd").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='SSD'){
		ssd = data.price;
		$("#ssd").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='DVD'){
		dvd = data.price;
		$("#dvd").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='사운드카드'){
		sound = data.price;
		$("#sound").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='운영체제'){
		os = data.price;
		$("#os").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}else if(data.category=='메모리'){
		memory = data.price;
		$("#memory").html(data.name);
		if(data.fileName==null){
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/No_image.jpg'>");
		}else{
			$("#picture").html("<img height='244px' width='244px' src='/droowa/product-img/"+data.fileName+"'>");
		}
	}
	
	sum = cpu+mainboard+cooler+memory+graphic+hdd+ssd+dvd+sound+power+kase+os;
	$("#completePrice").val(sum);
}